<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>获得元素的位置</title>
		<style>
			*{margin: 0; padding: 0;}
		</style>
		<script>
			function showSearchPos()
			{
				//alert(search.innerHTML);
				var search=document.getElementById("search");
				var d=search;
				var l=d.offsetTop;
				while(d.offsetParent!=null)
				{
					d=d.offsetParent;
					l+=d.offsetTop;
				}
				
				alert(l);
			}
		</script>
	</head>
	<body>
		<div class="sw-mn">
<div class="sw-mn-bd cl">

<div class="sw-mn-l z">
<ul><li><a href="javascript:;"  onclick="setHomepage('http://www.softwhy.com/');">设为首页</a></li><li><a href="http://www.softwhy.com/"  onclick="addFavorite(this.href, '蚂蚁部落');return false;">收藏本站</a></li></ul>
</div>

<div class="sw-mn-r y"><ul>
<li><a href="member.php?mod=logging&amp;action=login" onclick="" rel="nofollow">登录</a></li>
<li><a href="member.php?mod=register" class="xi2">立即注册</a></li>
</ul>
</div>

</div>
</div>

		<div id="top" style="height: 240px;margin: 10px;">
		<div id="head" style="border: 1px solid red;height: 140px;"></div>
		<div id="nav" style="border: 2px dotted green; padding: 40px;">
			<div id="search" style="border: 1px groove blue;">
				BAidu
			</div>
		</div>
		</div>
		<input type="button" value="显示search的位置" onclick="showSearchPos()"/>
	</body>
</html>
